package com.qigao.mall.web.job;

import com.qigao.mall.api.PayService;
import com.qigao.mall.jdbc.model.TbPayDetail;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author luiz
 * @Title: com.qigao.mall.web.job
 * @ProjectName three-mall
 * @date 2019-11-2019/11/20 10:42
 * @Description:支付信息相关job
 */
@Component
@Slf4j
public class PayJob {
    @Resource
    private PayService payService;
    /**
     * 每个30秒查询并补偿3分钟之前的支付订单状态
     */
    //@Scheduled(fixedRate = 30000)
    public void checkStatus(){
        //1.获取支付中并且补偿次数小于5的所有订单
        List<TbPayDetail> tbPayDetails=payService.findUnPayList();
        if(tbPayDetails==null || tbPayDetails.size()==0){
            return;
        }
        log.info("需要补偿查询处理的支付订单数:{}",tbPayDetails.size());
        for(TbPayDetail tbPayDetail:tbPayDetails){
            log.info("目前正在补偿处理的支付订单:{}",tbPayDetail.getPaySeqNo());
           payService.retryQueryPay(tbPayDetail);
        }
    }

    /**
     * 每300秒关闭未支付(超过120分钟未支付)订单
     *
     */
   // @Scheduled(fixedRate = 300000)
    public void closePay(){
        //1.获取支付中并且补偿次数小于5的所有订单
        List<TbPayDetail> tbPayDetails=payService.findNotPayList();
        if(tbPayDetails==null || tbPayDetails.size()==0){
            return;
        }
        log.info("需要处理未支付订单数:{}",tbPayDetails.size());
        for(TbPayDetail tbPayDetail:tbPayDetails){
            log.info("目前正在处理未支付订单:{}",tbPayDetail.getPaySeqNo());
            payService.retryQueryPay(tbPayDetail);
        }
    }

}


